package com.lianxueda.drawing.mapper;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.lianxueda.drawing.domain.pojo.Students;
import com.lianxueda.drawing.domain.vo.StudentCourseVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
* @author 28575
* @description 针对表【students】的数据库操作Mapper
* @createDate 2024-08-15 14:40:18
* @Entity cn/lianxueda/drawing.domain.Students
*/
@Mapper
public interface StudentsMapper extends BaseMapper<Students> {

    Integer getIdByName(String studentName);

    @Select("SELECT * FROM students WHERE parent_phone = #{phone} AND name = #{name}")
    Students findByPhoneNumberAndName(@Param("phone") String phone, @Param("name") String name);

    List<Students> selectByCourseIds(List<Integer> courseIds);



//    @Select("SELECT c.name FROM courses c " +
//            "JOIN course_student sc ON c.id = sc.course_id " +
//            "WHERE sc.student_id = #{studentId}")
//    String getCourseNameByStudentId(@Param("studentId") Integer studentId);

    @Select("SELECT c.name " +
            "FROM courses c " +
            "JOIN course_student cs ON c.id = cs.course_id " +
            "WHERE cs.student_id = #{id}")
    List<String> getCourseNamesByStudentId(@Param("id") Integer id);

    List<Students> getStudentsByIds(@Param("studentIds")  List<Integer> studentIds);

//    List<Students> getStudentsByIdsWithStatus(@Param("studentIds") List<Integer> studentIds);
List<Students> getStudentsByIdsWithStatus(@Param("studentIds") List<Integer> studentIds,
                                          @Param("courseId") Integer courseId,
                                          @Param("schedelesId") Integer schedelesId);

@Select("SELECT name FROM students WHERE id = #{studentId}")
    String findNameById(@Param("studentId") Integer studentId);

    @Select("<script>" +
            "SELECT * FROM students WHERE id IN " +
            "<foreach item='id' collection='studentIds' open='(' separator=',' close=')'>" +
            "#{id}" +
            "</foreach>" +
            "</script>")
    List<Students> selectByIds(@Param("studentIds") List<Integer> studentIds);

    @Select("SELECT name FROM students WHERE id = #{studentId}")
    String getStudentNameBy(@Param("studentId") Integer studentId);
}





